package com.loan.web.pdf.controller.create;

import com.loan.common.annotation.Log;
import com.loan.common.core.controller.BaseController;
import com.loan.common.core.domain.AjaxResult;
import com.loan.common.core.page.TableDataInfo;
import com.loan.common.enums.BusinessType;
import com.loan.common.utils.poi.ExcelUtil;
import com.loan.system.create.domain.AssistPdfCreateFile;
import com.loan.system.create.service.IAssistPdfCreateFileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * PDF文件生成记录Controller
 *
 * @author Sophia
 * @date 2024-08-12
 */
@RestController
@RequestMapping("/system/cfile")
public class AssistPdfCreateFileController extends BaseController {
    @Autowired
    private IAssistPdfCreateFileService assistPdfCreateFileService;

    /**
     * 查询PDF文件生成记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:cfile:list')")
    @GetMapping("/list")
    public TableDataInfo list(AssistPdfCreateFile assistPdfCreateFile) {
        startPage();
        List<AssistPdfCreateFile> list = assistPdfCreateFileService.selectAssistPdfCreateFileList(assistPdfCreateFile);
        return getDataTable(list);
    }

    /**
     * 导出PDF文件生成记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:cfile:export')")
    @Log(title = "PDF文件生成记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AssistPdfCreateFile assistPdfCreateFile) {
        List<AssistPdfCreateFile> list = assistPdfCreateFileService.selectAssistPdfCreateFileList(assistPdfCreateFile);
        ExcelUtil<AssistPdfCreateFile> util = new ExcelUtil<AssistPdfCreateFile>(AssistPdfCreateFile.class);
        util.exportExcel(response, list, "PDF文件生成记录数据");
    }

    /**
     * 获取PDF文件生成记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:cfile:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(assistPdfCreateFileService.selectAssistPdfCreateFileById(id));
    }

    /**
     * 新增PDF文件生成记录
     */
    @PreAuthorize("@ss.hasPermi('system:cfile:add')")
    @Log(title = "PDF文件生成记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AssistPdfCreateFile assistPdfCreateFile) {
        return toAjax(assistPdfCreateFileService.insertAssistPdfCreateFile(assistPdfCreateFile));
    }

    /**
     * 修改PDF文件生成记录
     */
    @PreAuthorize("@ss.hasPermi('system:cfile:edit')")
    @Log(title = "PDF文件生成记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AssistPdfCreateFile assistPdfCreateFile) {
        return toAjax(assistPdfCreateFileService.updateAssistPdfCreateFile(assistPdfCreateFile));
    }

    /**
     * 删除PDF文件生成记录
     */
    @PreAuthorize("@ss.hasPermi('system:cfile:remove')")
    @Log(title = "PDF文件生成记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(assistPdfCreateFileService.deleteAssistPdfCreateFileByIds(ids));
    }
}
